<?php

namespace bee;

define("PANNEL_WRAP_NODE",     0);
define("PANNEL_WRAP_DIV",      1);
define("PANNEL_WRAP_TABLE",    2);
define("PANNEL_WRAP_TD",       3);
define("PANNEL_WRAP_SPAN",     4);

/**
 * NE KORISTITI F U C K I N __parent izaziva crash PHP a prilikom serijalizacije (vjerojatno zbog rekurzivnih veza)
 * @author dzelenika
 *
 */
abstract class webPane extends object
{
  public    $__withEvents      = true;
  public    $__caption         = "w e b P a n e";
  public    $__width           = 500;
  public    $__height          = 100;
  public    $__wrapper         = PANNEL_WRAP_DIV;
  public    $__name            = "webPane";
  public    $__visible         = true;

  //protected $__dispatcher;
  protected $__DSDoc;
  public    $__fired;
  //protected $__app;
  //public    $__parent;  //

  public function __construct()
  {// $this->initializeMe();
    $dispatcher        = dispatcher::getInstance();

    $this->__DSDoc             = XMLDataHub::getInstance();
    $this->__fired             = false;
    //$this->__app               = app::getInstance();
    $dispatcher->addObject($this);// možda vratiti u 35???
  }

  public function __wakeup()
  {
    //$this->initializeMe();

    $dispatcher        = dispatcher::getInstance();
    $this->__fired     = true;

    $this->__DSDoc             = XMLDataHub::getInstance();
//     if(!$this->__app)
//     { $this->__app             = app::getInstance();
//     }
    $dispatcher->addObject($this); // možda vratiti u46
    //static::$__app           = app::getInstance();

  }

  private function initializeMe()
  {
    if($this)
    { $dispatcher      = dispatcher::getInstance();
      $dispatcher->addObject($this);
      $this->__DSDoc           = XMLDataHub::getInstance();
//       if(!$this->__app)
//       { $this->__app             = app::getInstance();
//       }
    }
  }

  public function onCreate($evt)
  { //die(": 1. kreiram :");
  }

  public function onLoad($evt)
  { //die(": 2. učitavam :");
  }

  public function doEvents($evt)
  { //die(": 3. događaji :");
  }

  public function onDraw($evt)
  {
    $this->fillDSDoc();
    //die(": 4 . crtam :");
    //print_r($this);
    //

  }

  public function unLoad($evt)
  { //die(": 5. zatvaram :");
  }


  public function fillDSDoc($fillVar = "")
  {
    $dsDoc = XMLDataHub::getInstance();
    if($fillVar)
    { //$this->__DSDoc->setVariable($fillVar, $this->value);
      $dsDoc->setVariable($fillVar, $this->value);
    }

    //die (print_r($this, true));
    $dsDoc->setObject("/form/widgets/" . $this->__name, $this);
    //$this->__DSDoc->setObject("/form/widgets/" . $this->__name, $this);
  }

//   public function fillDSDoc($fillVar = "")
//   {
//     if($fillVar)
//     { $this->__DSDoc->setVariable($fillVar, $this->value);
//     }

//     //die (print_r($this, true));
//     $this->__DSDoc->setObject("/form/widgets/" . $this->__name, $this);
//   }
}